﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using CoDbObject;
using Colligate.DataSource.DriverTraining;
using SZJT.Utility;
using System.Data;

namespace Colligate.DataSource.DriverTraining.Business.Coach
{
    public class BusinessCoachScheduleInfo : BaseLegoModule
    {
        private const string TABLE_COACH_SCHEDULE_INFO = "BusinessCoachScheduleInfo";
        private const string PROC_COACH_SCHEDULE_DETAILS = "CoachScheduleProcedure";

        public BusinessCoachScheduleInfo(IDataSourceLayer dataLayer)
            : base(new string[] { TABLE_COACH_SCHEDULE_INFO }, dataLayer)
        {
        }

        #region 返回Lego模块涉及到的数据名称的结构信息
        /// <summary>
        /// 返回Lego模块涉及到的数据名称的结构信息
        /// </summary>
        /// <param name="strDataName">基础表名称</param>
        /// <returns>表结构信息</returns>
        override public IFieldInfo[] GetStructInfo(string strDataName)
        {
            // 建立IFieldInfo列表
            // CFieldInfo(字段名, 类型, 长度, 索引, 状态, 字段说明, 字段帮助, 显示的格式化字符串, 字段宽度, 关联记录)
            // 类型： text，byte，short，long，single，double，currency，date，logical，memo，binary
            // 索引： 0 无索引，1 重复索引，2 唯一索引，3 关键字段
            // 状态： 0 系统字段，>1显示信息的字段， 2 用于标识记录名称的字段

            IFieldInfo[] tableStructInfo;
            switch (strDataName)
            {
                case TABLE_COACH_SCHEDULE_INFO:	 // 教练工作日信息
                    tableStructInfo = new IFieldInfo[9];
                    tableStructInfo[0] = new CFieldInfo("fScheduleGuid", "text", 36, 2, 0, "教练工作日信息", "教练工作日信息", "", 52, 0);
                    tableStructInfo[1] = new CFieldInfo("fSchoolGuid", "text", 36, 0, 1, "驾校标识", "驾校标识", "", 52, 0);
                    tableStructInfo[2] = new CFieldInfo("fSchoolName", "text", 50, 0, 1, "驾校名称", "驾校名称", "", 52, 0);
                    tableStructInfo[3] = new CFieldInfo("fCoachGuid", "text", 36, 0, 1, "教练标识", "教练标识", "", 52, 0);
                    tableStructInfo[4] = new CFieldInfo("fCoachName", "text", 10, 0, 1, "教练姓名", "教练姓名", "", 52, 0);
                    tableStructInfo[5] = new CFieldInfo("fCoachCode", "text", 10, 0, 1, "教练工号", "教练工号", "", 52, 0);
                    tableStructInfo[6] = new CFieldInfo("fScheduleDate", "date", 0, 0, 1, "计划日期", "计划日期", "", 52, 0);
                    tableStructInfo[7] = new CFieldInfo("fIsWorkingDay", "text", 6, 0, 1, "是否是工作日[T:工作日|F:休息日]", "是否是工作日[T:工作日|F:休息日]", "", 52, 0);
                    tableStructInfo[8] = new CFieldInfo("fScheduleMemo", "memo", 0, 0, 1, "计划备注", "计划备注", "", 52, 0);
                    break;
                default: tableStructInfo = null; break;
            }
            return tableStructInfo;
        }
        #endregion

        #region InitialData

        public override void InitDataInfo()
        {
            this.DataLayer.CreateProcedure(GetStructGlobalName(PROC_COACH_SCHEDULE_DETAILS),
                   string.Format("SELECT        s.id, s.fScheduleGuid, c.fSchoolGuid, c.fSchoolName, c.fCoachGuid, c.fCoachName, c.fCoachCode, s.fScheduleDate, s.fIsWorkingDay, s.fScheduleMemo " +
                                 " FROM dbo.tBusinessCoachInfo AS c LEFT OUTER JOIN {0} AS s ON c.fCoachGuid = s.fCoachGuid " +
                                 " WHERE ISNULL(fScheduleDate,@fScheduleDate) = @fScheduleDate ORDER BY  c.fCoachName ", GetStructGlobalName(TABLE_COACH_SCHEDULE_INFO)));

        }

        #endregion

        #region 教练工作日信息
        public IDBDataObject GetCoachScheduleInfoData(string strDataGuid)
        {
            string tableName = GetStructGlobalName(TABLE_COACH_SCHEDULE_INFO);
            return DataLayer.GetDBDataObject(tableName, string.Format("fScheduleGuid = '{0}'", strDataGuid));
        }

        /// <summary>
        /// 通过查询过滤条件取得教练工作日信息，并按照教练名字排序。
        /// </summary>
        /// <param name="queryFilter">查询过滤条件</param>
        /// <returns></returns>
        public IDBBigObjectSet GetCoachScheduleInfoListByFilter(string queryFilter)
        {
            return DataLayer.GetDBBigObjectSet(GetStructGlobalName(TABLE_COACH_SCHEDULE_INFO), queryFilter, "fCoachName");
        }

        /// <summary>
        /// 通过查询过滤条件取得所有教练工作日信息，并按照教练名字排序。
        /// </summary>
        /// <param name="queryFilter">查询过滤条件</param>
        /// <returns></returns>
        public DataSet GetCoachScheduleViewByScheduleDate(string paramDate)
        {
            IQueryParameter[] paramsInfo = new CQueryParameter[1];
            paramsInfo[0] = new CQueryParameter("fScheduleDate", "date", paramDate);

            return DataLayer.GetViewData(GetStructGlobalName(PROC_COACH_SCHEDULE_DETAILS), paramsInfo);
        }
        #endregion

    }
}
